import requests


class IHRMmanageEmpApi:
    # 登录接口
    @classmethod
    def ihrm_login(cls):
        url = "http://ihrm-test.itheima.net/api/sys/login"
        head = {"Content-Type": "application/json"}
        body = {"mobile": "13800000002", "password": "123456"}
        reques = requests.post(url=url, headers=head, json=body)
        token = reques.json()['data']
        return token

    # 添加员工接口
    @classmethod
    def add_manage_api(cls, token, add_body):
        add_url = "http://ihrm-test.itheima.net/api/sys/user"
        add_header = {"Content-Type": "application/json", "Authorization": token}
        add_requs = requests.post(url=add_url, headers=add_header, json=add_body)
        add_re = add_requs.json().get("data").get("id")
        return add_re

    # 查询员工接口
    @classmethod
    def inq_manage_api(cls, add_id, token):
        inq_url = "http://ihrm-test.itheima.net/api/sys/user/" + add_id
        inq_header = {"Authorization": token}
        inq_requs = requests.get(url=inq_url, headers=inq_header)
        return inq_requs

    # 修改员工接口
    @classmethod
    def rev_manage_api(cls, add_id, token, rev_body):
        rev_url = "http://ihrm-test.itheima.net/api/sys/user/" + add_id
        rev_header = {"Content-Type": "application/json", "Authorization": token}
        rev_requs = requests.put(url=rev_url, headers=rev_header, json=rev_body)
        return rev_requs

    # 删除员工接口
    @classmethod
    def del_manage_api(cls, add_id, token):
        del_url = "http://ihrm-test.itheima.net/api/sys/user/" + add_id
        del_header = {"Authorization": token}
        del_requs = requests.delete(url=del_url, headers=del_header)
        return del_requs
